var Adv_skd=require("./Adv_skd")

var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("AssetsMap"),
    c = e("BundleNames"),
    l = e("GlobalParam"),
    d = e("Util"),
    u = e("GameData"),
    p = e("SkinLevelData"),
    h = e("SkinLevelViewSnake"),
    f = cc._decorator,
    _ = f.ccclass,
    y = f.property,
    m = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.btn_close = null), (t.btn_get = null), (t.btn_giveUp = null), (t.content = null), (t.isInit = !1), t
            );
        }
        return (
            a(t, e),
            (t.prototype.addEvent = function () {
                e.prototype.addEvent.call(this),
                    this.btn_close.on(game.EngineEventType.NodeEvent.click, this.onClock_btn_close, this),
                    this.btn_get.on(game.EngineEventType.NodeEvent.click, this.onClock_btn_get, this),
                    this.btn_giveUp.on(game.EngineEventType.NodeEvent.click, this.onClock_btn_close, this);
            }),
            (t.prototype.removeEvent = function () {
                e.prototype.removeEvent.call(this),
                    this.btn_close.off(game.EngineEventType.NodeEvent.click, this.onClock_btn_close, this),
                    this.btn_get.off(game.EngineEventType.NodeEvent.click, this.onClock_btn_get, this),
                    this.btn_giveUp.off(game.EngineEventType.NodeEvent.click, this.onClock_btn_close, this);
            }),
            (t.prototype.onClock_btn_close = function () {
                game.AudioManager.playBtnEffect(),
                    this.closeView(),
                    game.PopupManager.instance.showPopView(s.default.PopupMap.SettlementView, null, !1, !1);
            }),
            (t.prototype.onClock_btn_get = function () {
                var e = this;
                ad.adInterface.showRewardedVideo(null, null, function () {
                    e.lookAd_back(), (e.btn_get.active = !1), e.onClock_btn_close();
                });
            }),
            (t.prototype.refreshView = function () {
                for (
                    var e = {type: "", data: null}, t = p.SkinLevelData.instance.skinList, o = null, n = 0;
                    n < t.length;
                    n++
                )
                    (r = t[n]).isLock || (o = r);
                if (o) return (e.type = "skin"), (e.data = o), (this.param = e), void this.onInitView();
                var i = null,
                    a = l.default.DecorateData;
                for (n = 0; n < a.length; n++) {
                    var r = a[n];
                    if ("true" != d.default.getItem("dressItemLock" + r.index, "false")) {
                        i = r;
                        break;
                    }
                }
                i
                    ? ((e.type = "decorate"), (e.data = i), (this.param = e), this.onInitView())
                    : this.onClock_btn_close();

                    Adv_skd.default.instance.hideAllAdv();
                    Adv_skd.default.instance.showInterstitialAd();
                    Adv_skd.default.instance.showGridAdLeft();
                    Adv_skd.default.instance.showGridAdRight();

            }),
            (t.prototype.lookAd_back = function () {
                game.UIManager.instance.showToast("已获取"),
                    "skin" == this.param.type
                        ? (p.SkinLevelData.instance.upgrade_lock(this.param.data),
                          (u.default.instance.OldUserSkin = null),
                          (u.default.instance.UserSkin = this.param.data.index))
                        : (d.default.setItem("dressItemLock" + this.param.data.index, "true"),
                          d.default.setItem("dressItemUse" + u.default.instance.UserSkin, this.param.data.index + ""));
            }),
            (t.prototype.onInitView = function () {
                (this.isCache = !1), (this.content = this.node.getChildByName("content"));
                var e = this.content.getChildByName("SkinLevelViewSnake1").getChildByName("snake");
                if ("skin" == this.param.type) {
                    var t = e.getComponent(h.default);
                    this.isInit
                        ? t.refreshView(this.param.data, 5)
                        : ((this.isInit = !0), t.init(0.75, 7), t.refreshView(this.param.data, 5)),
                        (this.content.getChildByName("skin_name").getComponent(cc.Label).string =
                            this.param.data.chinese);
                } else e && e.destroy();
                if ("decorate" == this.param.type) {
                    this.content.getChildByName("skin_name").getComponent(cc.Label).string = this.param.data.chinese;
                    var o = game.BundleManager.instance
                        .getBundle(c.default.Game)
                        .get(
                            s.default.GameBundle.textures.assetsList["decorate_icon_" + this.param.data.index],
                            cc.SpriteFrame
                        );
                    this.content.getChildByName("icon_image").getComponent(cc.Sprite).spriteFrame = o;
                } else this.content.getChildByName("icon_image").getComponent(cc.Sprite).spriteFrame = null;
            }),
            r([y(cc.Node)], t.prototype, "btn_close", void 0),
            r([y(cc.Node)], t.prototype, "btn_get", void 0),
            r([y(cc.Node)], t.prototype, "btn_giveUp", void 0),
            r([_], t)
        );
    })(game.BasePopView);
i.default = m;
